<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/common/base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
<link href="${ctsCss}/table.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%@ include file="/common/message-save.jsp" %>
<form id="dataItem-form" class="form-horizontal" action="${ctx}/dataItem/<c:choose><c:when test="${dataItem.id == null}">insert</c:when><c:otherwise>update</c:otherwise></c:choose>" method="post">
	<input type="hidden" id="id" name="id" value="${dataItem.id}"/>
<table>
	 <tr class="tab_grey">
      <td width="15%">字段名：</td>
      <td width="35%"><input type="text" id="itemName" name="itemName" value="${dataItem.itemName }" required maxlength="90" style="width:210px" /></td>
      
     </tr>
     <tr class="tab_grey">
     	<td width="15%">中文名称：</td>
     	<td width="35%"><input type="text" id="itemChineseName" name="itemChineseName" value="${dataItem.itemChineseName }" required maxlength="80" style="width:210px" /></td>
     </tr>
     <tr class="tab_grey">
     	<td width="15%">所属表名：</td>
     	<td width="35%">
     		<select id="setId" name="setId" required>
				   <option value="">请选择..</option>
				   <c:forEach var="dataSet" items="${dataSetList}">
					   <option value="${dataSet.id}" ${dataSet.id==dataItem.setId?'selected':''}>${dataSet.chineseName}</option>
				   </c:forEach>
			</select>
     	</td>
     </tr>
     <tr class="tab_grey">
     	<td width="15%">类型：</td>
     	<td width="35%">
     		<select id="keyType" name="keyType" required>
				   <option value="">请选择..</option>
				   <option value=1 ${dataItem.keyType==1?'selected':''}>主键</option>
				   <option value=2 ${dataItem.keyType==2?'selected':''}>外键</option>
				   <option value=3 ${dataItem.keyType==3?'selected':''}>其他</option>
			</select>
     	</td>
     </tr>
     <tr class="tab_grey">
     	<td width="15%">字段属性：</td>
     	<td width="35%">
     		<select id="valType" name="valType" required>
				   <option value="">请选择..</option>
				   <option value=1 ${dataItem.valType==1?'selected':''}>字符串</option>
				   <option value=2 ${dataItem.valType==2?'selected':''}>数字</option>
				   <option value=3 ${dataItem.valType==3?'selected':''}>时间</option>
			</select>
     	</td>
     </tr>
     <tr class="tab_grey">
     	<td width="15%">是否需要下拉框：</td>
     	<td width="35%">
     		<input type="radio" id="isSelect1" name="isSelect" checked="checked" value="1" onclick="isSelectFun();"/>否
     		<input type="radio" id="isSelect2" name="isSelect" value="2" onclick="isSelectFun();"/>是
     		<input type="hidden" value="${dataItem.isSelect}" id="isSelectHidden"/>
     	</td>
     </tr>
     <tr class="tab_grey" id="selectTableNameTr" style="display: none">
     	<td width="15%">下拉框所属表：</td>
     	<td width="35%">
			<input type="text" id="selectTableName" name="selectTableName" value="${dataItem.selectTableName}" maxlength="150" required style="width:210px" />
     	</td>
     </tr>
</table>
<div  style="text-align: center;">
	<button type="button" class="btn btn-primary" id="saveBtn" onclick="itemSaveInfo();">保存</button>
	<button type="reset" class="btn" id="resetBtn">重置</button>
</div>
</form>
</body>
<script type="text/javascript">
$('#dataItem-form').validate();
function itemSaveInfo(){
	var itemChineseName=document.getElementById("itemChineseName").value;
	//var itemId=document.getElementById("id").value;
	var itemId = $("#id").val();
	//判断下拉框的字段属性
	var isSelectValue = $('input[name="isSelect"]:checked').val();
	if(isSelectValue != "2"){
		$("#selectTableName").val("");
	}
	if(itemId == null || itemId == ""){
		$("#dataItem-form").submit();
	}else{
		var keyType=$("#keyType").val();
		var setId=$("#setId").val();
		$.ajax({
			url:'${ctx}/dataItem/check/'+itemChineseName+'/'+itemId+'/'+keyType+'/'+setId,
			type:'POST',
			cache:false,
			success:function(data){
				if(data == 0){
					$("#dataItem-form").submit();
				}else{
					layer.alert('字段中文名不能重复，请重新输入！');
					//$.ligerDialog.error('操作失败');
				}
			}
		});
	}
}

function isSelectFun(){
	var isSelectValue = $('input[name="isSelect"]:checked').val();
	if(isSelectValue == '2'){
		$("#selectTableNameTr").show();
	}else{
		$("#selectTableNameTr").hide();
	}
}

$(document).ready(function(){//初始化
	var isSelectHiddenVal = $("#isSelectHidden").val();
	if(isSelectHiddenVal == '2'){
		$("#isSelect2").attr("checked","checked");
		$("#selectTableNameTr").show();
	}else{
		$("#isSelect1").attr("checked","checked");
		$("#selectTableNameTr").hide();
	}
});

</script>
</html>